﻿using System;
using System.Windows;
using JiaBao.Core.Infrastructure;
using JiaBao.Services.LogService;
using JiaBao.WPF.Framework.SN;

namespace JiaBao.WPF
{
    /// <summary>
    /// Register.xaml 的交互逻辑
    /// </summary>
    public partial class W_Register : Window
    {
        Register register = EngineContext.Current.Resolve<Register>();
        public W_Register()
        {
            InitializeComponent();


            txt_Key.Text = register.Key;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var m = new RegisterManager();
                if (register.IsTest)
                { 
                    if (txt_Sn.Text.Trim() ==m.GetSN ( m.GetSN(register.Key)))
                    {
                        register.LocalSn = DateTime.Now.AddDays(7).ToFileTimeUtc().ToString();
                        m.SaveSettings(register);
                        DialogResult = true;
                        this.Close();
                        return;
                    } 
                }
                else if (txt_Sn.Text.Trim() == register.Sn)
                {
                    register.LocalSn = txt_Sn.Text.Trim();
                    m.SaveSettings(register);
                    DialogResult = true;
                    this.Close();
                    return;
                } 
                MessageBox.Show("注册码错误"); 
            }
            catch (Exception ex)
            {
                Log.SaveLog(ex);
                MessageBox.Show(ex.Message);
            }


        }
    }
}
